<template>
  <div>
    <a-empty v-if="viewId.length===0" description="暂无视图信息"></a-empty>
    <div v-else>
      <a-form class="form">
        <a-form-item label="视图名称">
          <ZgInput v-model="obj.name" :disabled="obj.type!=='form'"></ZgInput>
        </a-form-item>
        <a-form-item label="视图类型">
          <ZgDictionary disabled code="viewType" v-model="obj.type"></ZgDictionary>
        </a-form-item>
        <a-form-item label="视图标题">
          <ZgInput v-model="obj.title"></ZgInput>
        </a-form-item>
        <a-form-item label="显示标题">
          <ZgSwitch v-model="obj.showTitle"></ZgSwitch>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    viewId: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      obj: {
        id: '',
        name: '',
        type: '',
        title: '',
        showTitle: false
      }
    }
  },
  watch: {
    viewId () {
      this.search()
    }
  },
  mounted () {
    this.search()
  },
  methods: {
    search () {
      if (this.viewId.length === 0) {
        return
      }
      this.$http.get('/zg-autoform/zxb/view/info', { id: this.viewId }, info => {
        this.obj = info
      })
    },
    save () {
      if (this.obj.name.length === 0) {
        this.$warning({ title: '请输入视图名称' })
        return
      }
      if (this.obj.type.length === 0) {
        this.$warning({ title: '请选择视图类型' })
        return
      }
      if (this.obj.showTitle && this.obj.title.length === 0) {
        this.$warning({ title: '请设置视图标题' })
        return
      }
      this.$http.post('/zg-autoform/zxb/view/update', this.obj, () => {
        this.$success({ title: '操作成功！' })
        this.$emit('ok', this.obj)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
